Next: Accessing Slots, Previous: Building Classes, Up: Top [Contents][Index]
Suppose we have a simple class is defined, such as:
(defclass record () ( ) "Doc String")
It is now possible to create objects of that class type.
Calling defclass has defined two new functions.
One is the constructor record, and the other is the
predicate, record-p.
This creates and returns a new object. This object is not
assigned to anything, and will be garbage collected if not
saved. This object will be given the string name
object-name. There can be multiple objects of the
same name, but the name slot provides a handy way to keep
track of your objects. slots is just all the slots
you wish to preset. Any slot set as such will not
get its default value, and any side effects from a
slot’s :initform that may be a function
will not occur.
An example pair would appear simply as :value
1. Of course you can do any valid Lispy thing you want
with it, such as :value (if (boundp 'special-symbol)
special-symbol nil)
Example of creating an object from a class:
(record :value 3 :reference nil)
To create an object from a class symbol, use
make-instance.
Make a new instance of class based on initargs. class is a class symbol. For example:
(make-instance 'foo)
initargs is a property list with keywords based
on the :initarg for each slot. For example:
(make-instance'foo:slot1value1:slotNvalueN)
Next: Accessing Slots, Previous: Building Classes, Up: Top [Contents][Index]